/************************************************************************
                                                                     
   Xceed Ultimate ListBox for Silverlight                                                                                                                                            
   Copyright (C) 2010 Xceed Software Inc.    
                                                                     
   This program is provided to you under the terms of the GNU General Public  
   License version 2 as published by the Free Software Foundation. 
        
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY, without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along 
   with this program, if not, write to the Free Software Foundation, Inc., 
   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. Visit Xceed.com to find the commercial edition of 
   Xceed Ultimate ListBox for Silverlight.                                    
                                                                      
 **********************************************************************/

using System;
using System.Windows;
using System.Windows.Media.Animation;

namespace Xceed.Silverlight.ListBox
{
  public class ListBoxAnimationSettings : DependencyObject
  {
    #region Constructor

    static ListBoxAnimationSettings()
    {
      ListBoxAnimationSettings.DefaultEasingFunctionProperty = DependencyProperty.Register( 
        "DefaultEasingFunction",
        typeof( EasingFunctionBase ),
        typeof( ListBoxAnimationSettings ),
        new PropertyMetadata( new PowerEase()
        {
          Power = 3,
          EasingMode = EasingMode.EaseOut
        } ) );
    }

    #endregion

    #region DefaultDuration Property

    public static readonly DependencyProperty DefaultDurationProperty = DependencyProperty.Register(
      "DefaultDuration",
      typeof( TimeSpan ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( new TimeSpan( 0, 0, 0, 0, 750 ), new PropertyChangedCallback( ListBoxAnimationSettings.OnDefaultDurationChanged ) ) );

    private static void OnDefaultDurationChanged( object sender, DependencyPropertyChangedEventArgs e )
    {
      if( e.NewValue == null )
      {
        throw new ArgumentNullException( "DefaultDuration" );
      }
    }

    public TimeSpan DefaultDuration
    {
      get
      {
        return ( TimeSpan )this.GetValue( ListBoxAnimationSettings.DefaultDurationProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.DefaultDurationProperty, value );
      }
    }

    #endregion

    #region DefaultEasingFunction Property

    public static readonly DependencyProperty DefaultEasingFunctionProperty;

    public EasingFunctionBase DefaultEasingFunction
    {
      get
      {
        return ( EasingFunctionBase )this.GetValue( ListBoxAnimationSettings.DefaultEasingFunctionProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.DefaultEasingFunctionProperty, value );
      }
    }

    #endregion

    #region PageScrollingDuration Property

    public static readonly DependencyProperty PageScrollingDurationProperty = DependencyProperty.Register(
      "PageScrollingDuration",
      typeof( Nullable<TimeSpan> ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( Nullable<TimeSpan> )null ) );

    public Nullable<TimeSpan> PageScrollingDuration
    {
      get
      {
        return ( Nullable<TimeSpan> )this.GetValue( ListBoxAnimationSettings.PageScrollingDurationProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.PageScrollingDurationProperty, value );
      }
    }

    #endregion

    #region PageScrollingEasingFunction Property

    public static readonly DependencyProperty PageScrollingEasingFunctionProperty = DependencyProperty.Register(
      "PageScrollingEasingFunction",
      typeof( EasingFunctionBase ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( EasingFunctionBase )null ) );

    public EasingFunctionBase PageScrollingEasingFunction
    {
      get
      {
        return ( EasingFunctionBase )this.GetValue( ListBoxAnimationSettings.PageScrollingEasingFunctionProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.PageScrollingEasingFunctionProperty, value );
      }
    }

    #endregion

    #region LineScrollingDuration Property

    public static readonly DependencyProperty LineScrollingDurationProperty = DependencyProperty.Register(
      "LineScrollingDuration",
      typeof( Nullable<TimeSpan> ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( Nullable<TimeSpan> )null ) );

    public Nullable<TimeSpan> LineScrollingDuration
    {
      get
      {
        return ( Nullable<TimeSpan> )this.GetValue( ListBoxAnimationSettings.LineScrollingDurationProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.LineScrollingDurationProperty, value );
      }
    }

    #endregion

    #region LineScrollingEasingFunction Property

    public static readonly DependencyProperty LineScrollingEasingFunctionProperty = DependencyProperty.Register(
      "LineScrollingEasingFunction",
      typeof( EasingFunctionBase ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( EasingFunctionBase )null ) );

    public EasingFunctionBase LineScrollingEasingFunction
    {
      get
      {
        return ( EasingFunctionBase )this.GetValue( ListBoxAnimationSettings.LineScrollingEasingFunctionProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.LineScrollingEasingFunctionProperty, value );
      }
    }

    #endregion

    #region ThumbScrollingDuration Property

    public static readonly DependencyProperty ThumbScrollingDurationProperty = DependencyProperty.Register(
      "ThumbScrollingDuration",
      typeof( Nullable<TimeSpan> ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( Nullable<TimeSpan> )null ) );

    public Nullable<TimeSpan> ThumbScrollingDuration
    {
      get
      {
        return ( Nullable<TimeSpan> )this.GetValue( ListBoxAnimationSettings.ThumbScrollingDurationProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.ThumbScrollingDurationProperty, value );
      }
    }

    #endregion

    #region ThumbScrollingEasingFunction Property

    public static readonly DependencyProperty ThumbScrollingEasingFunctionProperty = DependencyProperty.Register(
      "ThumbScrollingEasingFunction",
      typeof( EasingFunctionBase ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( EasingFunctionBase )null ) );

    public EasingFunctionBase ThumbScrollingEasingFunction
    {
      get
      {
        return ( EasingFunctionBase )this.GetValue( ListBoxAnimationSettings.ThumbScrollingEasingFunctionProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.ThumbScrollingEasingFunctionProperty, value );
      }
    }

    #endregion

    #region LoadingDuration Property

    public static readonly DependencyProperty LoadingDurationProperty = DependencyProperty.Register(
      "LoadingDuration",
      typeof( Nullable<TimeSpan> ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( Nullable<TimeSpan> )null ) );

    public Nullable<TimeSpan> LoadingDuration
    {
      get
      {
        return ( Nullable<TimeSpan> )this.GetValue( ListBoxAnimationSettings.LoadingDurationProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.LoadingDurationProperty, value );
      }
    }

    #endregion

    #region AddingItemDuration Property

    public static readonly DependencyProperty AddingItemDurationProperty = DependencyProperty.Register(
      "AddingItemDuration",
      typeof( Nullable<TimeSpan> ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( Nullable<TimeSpan> )null ) );

    public Nullable<TimeSpan> AddingItemDuration
    {
      get
      {
        return ( Nullable<TimeSpan> )this.GetValue( ListBoxAnimationSettings.AddingItemDurationProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.AddingItemDurationProperty, value );
      }
    }

    #endregion

    #region RemovingItemDuration Property

    public static readonly DependencyProperty RemovingItemDurationProperty = DependencyProperty.Register(
      "RemovingItemDuration",
      typeof( Nullable<TimeSpan> ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( Nullable<TimeSpan> )null ) );

    public Nullable<TimeSpan> RemovingItemDuration
    {
      get
      {
        return ( Nullable<TimeSpan> )this.GetValue( ListBoxAnimationSettings.RemovingItemDurationProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.RemovingItemDurationProperty, value );
      }
    }

    #endregion

    #region ViewChangingDuration Property

    public static readonly DependencyProperty ViewChangingDurationProperty = DependencyProperty.Register(
      "ViewChangingDuration",
      typeof( Nullable<TimeSpan> ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( Nullable<TimeSpan> )null ) );

    public Nullable<TimeSpan> ViewChangingDuration
    {
      get
      {
        return ( Nullable<TimeSpan> )this.GetValue( ListBoxAnimationSettings.ViewChangingDurationProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.ViewChangingDurationProperty, value );
      }
    }

    #endregion

    #region ItemSizeChangingDuration Property

    public static readonly DependencyProperty ItemSizeChangingDurationProperty = DependencyProperty.Register(
      "ItemSizeChangingDuration",
      typeof( Nullable<TimeSpan> ),
      typeof( ListBoxAnimationSettings ),
      new PropertyMetadata( ( Nullable<TimeSpan> )null ) );

    public Nullable<TimeSpan> ItemSizeChangingDuration
    {
      get
      {
        return ( Nullable<TimeSpan> )this.GetValue( ListBoxAnimationSettings.ItemSizeChangingDurationProperty );
      }
      set
      {
        this.SetValue( ListBoxAnimationSettings.ItemSizeChangingDurationProperty, value );
      }
    }

    #endregion


    internal int GetLineScrollingDuration()
    {
      if( this.LineScrollingDuration.HasValue )
      {
        return ( int )this.LineScrollingDuration.Value.TotalMilliseconds;
      }

      return ( int )this.DefaultDuration.TotalMilliseconds;
    }

    internal int GetPageScrollingDuration()
    {
      if( this.PageScrollingDuration.HasValue )
      {
        return ( int )this.PageScrollingDuration.Value.TotalMilliseconds;
      }

      return ( int )this.DefaultDuration.TotalMilliseconds;
    }

    internal int GetThumbScrollingDuration()
    {
      if( this.ThumbScrollingDuration.HasValue )
      {
        return ( int )this.ThumbScrollingDuration.Value.TotalMilliseconds;
      }

      return ( int )this.DefaultDuration.TotalMilliseconds;
    }

    internal EasingFunctionBase GetLineScrollingEasingFunction()
    {
      if( this.LineScrollingEasingFunction != null )
      {
        return this.LineScrollingEasingFunction;
      }

      return this.DefaultEasingFunction;
    }

    internal EasingFunctionBase GetPageScrollingEasingFunction()
    {
      if( this.PageScrollingEasingFunction != null )
      {
        return this.PageScrollingEasingFunction;
      }

      return this.DefaultEasingFunction;
    }

    internal EasingFunctionBase GetThumbScrollingEasingFunction()
    {
      if( this.ThumbScrollingEasingFunction != null )
      {
        return this.ThumbScrollingEasingFunction;
      }

      return this.DefaultEasingFunction;
    }

    internal int GetLoadingDuration()
    {
      if( this.LoadingDuration.HasValue )
      {
        return ( int )this.LoadingDuration.Value.TotalMilliseconds;
      }

      return ( int )this.DefaultDuration.TotalMilliseconds;
    }

    internal int GetAddingItemDuration()
    {
      if( this.AddingItemDuration.HasValue )
      {
        return ( int )this.AddingItemDuration.Value.TotalMilliseconds;
      }

      return ( int )this.DefaultDuration.TotalMilliseconds;
    }

    internal int GetRemovingItemDuration()
    {
      if( this.RemovingItemDuration.HasValue )
      {
        return ( int )this.RemovingItemDuration.Value.TotalMilliseconds;
      }

      return ( int )this.DefaultDuration.TotalMilliseconds;
    }

    internal int GetViewChangingDuration()
    {
      if( this.ViewChangingDuration.HasValue )
      {
        return ( int )this.ViewChangingDuration.Value.TotalMilliseconds;
      }

      return ( int )this.DefaultDuration.TotalMilliseconds;
    }

    internal int GetItemSizeChangingDuration()
    {
      if( this.ItemSizeChangingDuration.HasValue )
      {
        return ( int )this.ItemSizeChangingDuration.Value.TotalMilliseconds;
      }

      return ( int )this.DefaultDuration.TotalMilliseconds;
    }
  }
}
